package net.helix.core;

import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;

public class Color {
	private float r = 1;
	private float g = 1;
	private float b = 1;
	private float a = 1;
	public Color(float r, float g, float b, float a){
		this.r = r;
		this.g = g;
		this.b = b;
		this.a = a;
	}
	public Color clone(){
		return new Color(getR(),getG(),getB(),a);
	}
	public void set(float r, float g, float b, float a){
		this.r = r;
		this.g = g;
		this.b = b;
		this.a = a;
		updateBuffer = true;
	}
	public float getR() {
		return r;
	}
	public void setR(float r) {
		this.r = r;
		updateBuffer = true;
	}
	public float getG() {
		return g;
	}
	public void setG(float g) {
		this.g = g;
		updateBuffer = true;
	}
	public float getB() {
		return b;
	}
	public void setB(float b) {
		this.b = b;
		updateBuffer = true;
	}
	private FloatBuffer buff = null;
	private boolean updateBuffer = true;
	public FloatBuffer getAsFloatBuffer(){
		if(buff == null){
			buff = BufferUtils.createFloatBuffer(4);
		}
		if(updateBuffer){
			buff.put(getR());
			buff.put(getG());
			buff.put(getB());
			buff.put(a);
			buff.flip();
		}
		updateBuffer = false;
		return buff;
	}
}
